package com.lechi.web.job;

import com.lechi.web.common.config.LeChiConfig;
import com.lechi.web.common.utils.DateUtils;
import com.lechi.web.common.utils.StringUtils;
import com.lechi.web.constants.Constants;
import com.lechi.web.framework.util.GuavaCacheUtil;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;

/**
 * 只负责生成文件名称，不生成文件
 *
 * @author yangguang
 */
@Slf4j
public class GetRecordFileNameJob implements Job {

    @Override
    public void execute(JobExecutionContext context) {
        String deviceId = String.valueOf(context.getMergedJobDataMap().get("deviceId"));
        String fileNamePreFix = String.valueOf(context.getMergedJobDataMap().get("fileName"));
        String txtFile = LeChiConfig.getRecordLogPath() + StringUtils.format("/{}/{}/{}{}.{}", deviceId, DateUtils.datePath(), fileNamePreFix, DateUtils.getYYYYMMDDHH(), "txt");
        String csvFile = LeChiConfig.getRecordLogPath() + StringUtils.format("/{}/{}/{}{}.{}", deviceId, DateUtils.datePath(), fileNamePreFix, DateUtils.getYYYYMMDDHH(), "csv");
        GuavaCacheUtil.getDeviceTableMap().put(Constants.WRITE_RECORD_LOG_TXT + deviceId, txtFile);
        GuavaCacheUtil.getDeviceTableMap().put(Constants.WRITE_RECORD_LOG_CSV + deviceId, csvFile);
    }
}